package com.dst.smart.handler.disposer;

import android.content.Context;
import android.util.Log;
import com.dst.smart.handler.entity.SemanticResult;
import com.dst.smart.handler.entity.ServiceType;

import org.json.JSONArray;

/**
 * 同义词近义词。
 * 	煎熬的近义词
 	安静的近义词是什么
 	哪个词是安静的近义词
 * 
 * author <a href="http://www.xfyun.cn">讯飞开放平台</a>
 * date 2016年9月5日 下午4:58:10
 *
 */
public class WordFindingDisposer extends Disposer {
	//private static final String KEY_URL = "url";

	public WordFindingDisposer(Context context) {
		super(context);
	}
	
	@Override
	public void disposeResult(final SemanticResult semanticResult) {
		try {
			if (semanticResult != null) {
				JSONArray result = semanticResult.getResult();
				if (result != null && result.length() > 0) {
					//MainActivity.playSound(4, semanticResult.getAnswerText());
					getPlayController().playURLList(semanticResult.getUUID(), null);
					getPlayController().playText(semanticResult.getUUID(), semanticResult.getAnswerText(), true, 0, "", null);
//				String resultTxt=semanticResult.getAnswerText();
//	            for (int i = 0; i < result.length(); i++) {
//					JSONObject jsonObject=result.getJSONObject(i);
//					String title =(i+1) +jsonObject.getString("title");
//					String answer="答案"+jsonObject.getString("answer");
//					resultTxt+=title+answer;
//	            }
					sendAiuiData("同义词近义词", "wordFinding", result.toString());
				} else {
					getPlayController().playURLList(semanticResult.getUUID(), null);
					getPlayController().playText(semanticResult.getUUID(), semanticResult.getAnswerText(), true, "", null);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public boolean canHandle(ServiceType type){
		return (type == ServiceType.WORDFINDING);
	}
}
